﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Reflection;

using MefContrib.Hosting.Generics;

using NuMetaheuristics;

namespace NuMetaheuristics.Utility
{
    public class Discoverer<T>
    {
        virtual public List<T> DiscoverObjects()
        {
            var directoryCatalog = new DirectoryCatalog(
                System.IO.Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location
                    )
                );

            var container = new CompositionContainer(directoryCatalog);
            IEnumerable<T> values = container.GetExportedValues<T>();
            return values.ToList();
        }

        public List<Type> DiscoverTypes()
        {
            List<T> objects = DiscoverObjects();
            List<Type> types = new List<Type>();

            for (int i = 0; i < objects.Count(); i++)
            {
                types.Add(objects[i].GetType());
            }
            
            return types;
        }
    }
}
